package com.wude.guild.views;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.wude.guild.R;
import com.wude.guild.face.HomeMenuFace;
import com.wude.http.NetWorkBroadcast;
import com.wude.tools.Utils;

/**
 * Created by Administrator on 2017/11/22 0022.
 */

public class HomeButtomMenu extends LinearLayout implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
    private Context context;

    private RadioGroup radioGroup;
    private RadioButton rb_home;
    private RadioButton rb_gifts;
    private RadioButton rb_shop;
    private RadioButton rb_information;
    private RadioButton rb_mcenter;
    private ImageView iv_icon;

    private HomeMenuFace face;

    public HomeButtomMenu(Context context, HomeMenuFace face) {
        super(context);
        this.context = context;
        this.face = face;
        initView();
    }

    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.home_buttom_menu, this);
        radioGroup = findViewById(R.id.rg_group);
        rb_home = findViewById(R.id.rb_home);
        rb_gifts = findViewById(R.id.rb_gifts);
        rb_shop = findViewById(R.id.rb_shop);
        rb_information = findViewById(R.id.rb_information);
        rb_mcenter = findViewById(R.id.rb_mcenter);
        iv_icon = findViewById(R.id.iv_icon);
        Tu();

        radioGroup.setOnCheckedChangeListener(this);
        rb_home.setChecked(true);
        iv_icon.setOnClickListener(this);
    }

    private void Tu() {
        int i = Utils.dipToPx(context, 20);
        Drawable home = getResources().getDrawable(R.drawable.tab_home_btn);
        home.setBounds(0, 0, i, i);
        rb_home.setCompoundDrawables(null, home, null, null);

        Drawable gift = getResources().getDrawable(R.drawable.tab_fenlei_btn);
        gift.setBounds(0, 0, i, i);
        rb_gifts.setCompoundDrawables(null, gift, null, null);

//        Drawable paihang = getResources().getDrawable(R.mipmap.fuli);
//        paihang.setBounds(0, 0, 0, 0);
//        rb_shop.setCompoundDrawables(null, paihang, null, null);


        Drawable information = getResources().getDrawable(R.drawable.tab_shop_btn);
        information.setBounds(0, 0, i, i);
        rb_information.setCompoundDrawables(null, information, null, null);

        Drawable me = getResources().getDrawable(R.drawable.tab_me_btn);
        me.setBounds(0, 0, i, i);
        rb_mcenter.setCompoundDrawables(null, me, null, null);
    }

    private void setTabSelection(int checkedId) {
        switch (checkedId) {
            case R.id.rb_home:
                face.home();
                break;
            case R.id.rb_gifts:
                face.message();
                break;
            case R.id.rb_shop:
                face.welfare();
//                onClick(rb_shop);
                break;
            case R.id.rb_information:
                face.shared();
                break;
            case R.id.rb_mcenter:
                face.mine();
                break;
        }
    }

    public void hashNew(boolean show) {
        if (show)
            iv_icon.setImageResource(R.mipmap.fuli_red);
        else
            iv_icon.setImageResource(R.mipmap.fuli);
    }

    @Override
    public void onClick(View view) {
        onCheckedChanged(radioGroup, R.id.rb_shop);
        rb_shop.setChecked(true);
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        setTabSelection(i);
    }
}
